﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MixScript.BLL.FI;
using System.Data;
using System.Globalization;

namespace MixScriptWeb.Accounting.ReportObject
{
    public partial class frmGeneralLedger : cCommonWeb, IMIxCommon // System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { LoadData(); }
            txtFrom.CssClass="input-small datepicker";
            txtTo.CssClass = "input-small datepicker";
        }
        private void LoadData()
        {
            DataTable dt = new DataTable();
            rptGeneralJournal gj = new rptGeneralJournal();
            gj.getActivePeriod(out dt);
            //FillDropDownList(ddlPeriod, dt, "Name", "ID", true);
            rbGlobal_CheckedChanges(null, null);
        }

        public bool isvalid()
        { return true; }
        protected void rbGlobal_CheckedChanges(Object sender, EventArgs e)
        {
            rptGeneralJournal gj = new rptGeneralJournal();
            DataTable dt = new DataTable();
            if (gj.getMataUang(out dt, 0))
            { }
            else { }
            gvList.DataSource = dt;
            gvList.DataBind();

        }
        protected void rbForeign_CheckedChanges(Object sender, EventArgs e)
        {
            rptGeneralJournal gj = new rptGeneralJournal();
            DataTable dt = new DataTable();
            if (gj.getMataUang(out dt, 1))
            { }
            else { }
            gvList.DataSource = dt;
            gvList.DataBind();
        }
        protected void rbPeriod_CheckedChanges(Object sender, EventArgs e)
        {
            //ddlPeriod.Enabled = rbPeriod1.Checked;
            //txtFrom.Enabled = rbPeriod2.Checked;
            //txtTo.Enabled = rbPeriod2.Checked;

        }
        protected void chkAllHeader_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkAll = new CheckBox();
            CheckBox chk;
            chkAll = (CheckBox)gvList.HeaderRow.Cells[0].FindControl("chkAllHeader");
            for (int i = 0; i < gvList.Rows.Count; i++)
            {
                chk = new CheckBox();
                chk = (CheckBox)gvList.Rows[i].Cells[0].FindControl("chkAll");
                chk.Checked = chkAll.Checked;

            }

        }
        protected void btnSubmit_Click(Object sender, EventArgs e)
        {
            String param = "";
            for (int i = 0; i < gvList.Rows.Count; i++)
            {
                CheckBox chk = new CheckBox();
                chk = (CheckBox)gvList.Rows[i].Cells[0].FindControl("chkAll");
                if (chk.Checked)
                {
                    if (param == "")
                        param = gvList.Rows[i].Cells[1].Text.TrimEnd();
                    else
                        param = param + "," + gvList.Rows[i].Cells[1].Text.TrimEnd();
                }
            }
            Session["ledgerParam"] = param;
            //if (rbPeriod1.Checked)
            //{
            //    Session["fromParam"] = null;
            //    Session["toParam"] = null;
            //}
            //{
            Session["fromParam"] = Convert.ToDateTime(txtFrom.Text, new CultureInfo("ru-RU"));
            Session["toParam"] = Convert.ToDateTime(txtTo.Text, new CultureInfo("ru-RU"));
            //            }



            ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW",
                "window.open( '/Accounting/ReportObject/rpt_GeneralLedger.aspx', null, '' );", true);

        }
    }
}